<template>
    <!-- 持股策略说明 -->
    <div class="">
        <h3 class="strategy-title">持仓股票涨跌幅</h3>
        <p class="strategy-desc">美股以前一天收盘数据为准,A、港股则按当天16:30更新为准</p>
        <!-- 涨跌幅最大股票卡片 -->
        <div class="stock-cards">
            <!-- 涨幅最大 -->
            <div>
                <h3 class="card-title">今日<span style="color: red">涨幅</span>最大</h3>
                <div class="stock-card gain-card">
                    <div class="stock-info">
                        <div class="stock-name">{{ max.name }}</div>
                        <!--                    <div class="stock-change">+{{max.pct_chg}}%</div>-->
                    </div>
                    <div class="stock-price">
                        <span class="price-label">持仓股数: </span>
                        <span class="price-value">{{max.num}}({{max.holding}})</span>
                    </div>
                    <div class="stock-volume">
                        <span class="volume-label">持仓盈利: </span>
                        <span class="volume-value">{{max.profit}}万</span>
                    </div>
                    <div class="stock-volume">
                        <span class="volume-label">今日涨跌: </span>
                        <span class="volume-value">{{max.pct_chg}}%</span>
                    </div>
                </div>
            </div>


            <!-- 跌幅最大 -->
            <div>
                <h3 class="card-title">今日<span style="color: green">跌幅</span>最大</h3>
                <div class="stock-card loss-card">
                    <div class="stock-info">
                        <div class="stock-name">{{min.name}}</div>
                        <!--                    <div class="stock-change">{{min.pct_chg}}%</div>-->
                    </div>
                    <div class="stock-price">
                        <span class="price-label">持仓股数: </span>
                        <span class="price-value">{{min.num}}({{min.holding}})</span>
                    </div>
                    <div class="stock-volume">
                        <span class="volume-label">持仓盈利: </span>
                        <span class="volume-value">{{min.profit}}万</span>
                    </div>
                    <div class="stock-volume">
                        <span class="volume-label">今日涨跌: </span>
                        <span class="volume-value">{{min.pct_chg}}%</span>
                    </div>
                </div>
            </div>

        </div>
    </div>
</template>

<script setup>
import {getDailyProfit} from "@/api/index";
import {onMounted, reactive} from "vue";

let max = reactive({
    name: '',
    holding: '',
    num: '',
    pct_chg: '',
    profit: '',
})
let min = reactive({
    name: '',
    holding: '',
    num: '',
    pct_chg: '',
    profit: '',
})

onMounted(() => {
    getDailyProfit().then(response => {
        Object.assign(max, response.data.data.max)
        Object.assign(min, response.data.data.min)
    })
})
</script>

<style scoped>
.stock-price,
.stock-volume,
.stock-profit {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.price-label,
.volume-label,
.profit-label {
    color: #666;
    margin-right: 8px;
}

.price-value,
.volume-value,
.profit-value {
    color: #333;
}

.strategy-title {
    color: #333;
    margin: 0 0 8px 0;
}

.strategy-desc {
    color: #a2a2a2;
    margin: 0;
}

/* 股票卡片 */
.stock-cards {
    font-size: 24px;
    margin-top: 30px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 100px;
    margin-bottom: 24px;
}

.stock-card {
    background-color: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.gain-card {
    border-left: 4px solid #ff3b30;
}

.loss-card {
    border-left: 4px solid green;
}

.card-title {
    padding: 0px 24px;
    color: #333;
    margin: 0 0 16px 0;
}

.stock-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.stock-name {
    font-weight: bold;
    color: #333;
}

.gain-card .stock-change {
    font-weight: bold;
    color: #ff3b30;
}

.loss-card .stock-change {
    font-weight: bold;
    color: green;
}

@media (max-width: 480px) {
    .stock-cards {
        color: #FFFFFFFF;
        font-size: 14px;
        margin-top: 30px;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
        margin-bottom: 24px;
    }
    .stock-card{
        border-radius: 12px;
        padding: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    .price-value,
    .volume-value,
    .profit-value {
        color: #ffffff;
    }
    .stock-name {
        font-weight: bold;
        color: #fff;
    }
    .card-title {
        color: #333;
        padding-left: 10px;
        margin: 0 0 5px 0;
    }
    .gain-card {
        background-color: rgb(255, 93, 106);
    }

    .loss-card {
        background-color: rgb(90, 212, 199);
        border-left: 4px solid rgb(90, 212, 199);
    }
    .price-label,
    .volume-label,
    .profit-label {
        color: #fff;
        margin-right: 8px;
    }
    .stock-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0px;
    }
}
</style>
